/**
 * Copyright (c) 2020 xstgongyi.org
 * All rights reserved.
 */
package org.xstgongyi.eduaid.manager;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.xstgongyi.eduaid.dao.SemesterMapper;
import org.xstgongyi.eduaid.dataobject.SemesterDO;

import java.util.List;

/**
 * manager层代码，作为module的内部代码，不应该被module外部调用，也不应该被service之上各层调用。 调用者需要保证参数的合法性。
 *
 * @author oldcrane
 * @created 2020-10-12
 */

@Service
@CacheConfig(cacheNames = "semester")
public class SemesterManager {

    @Autowired
    private SemesterMapper semesterDao;

    @Cacheable(key = "'list-all'")
    public List<SemesterDO> listAll() {
        return semesterDao.listAll();
    }

    @Cacheable(key = "'list-status-' + #active")
    public List<SemesterDO> listAllByStatus(Boolean active) {
        return semesterDao.listAllByStatus(active);
    }

    @Cacheable(key = "#id")
    public SemesterDO getById(Integer id) {
        return semesterDao.getById(id);
    }

    @CacheEvict(allEntries = true)
    public int insert(SemesterDO semester) {
        return semesterDao.insert(semester);
    }

    @CacheEvict(allEntries = true)
    public int update(SemesterDO semester) {
        return semesterDao.update(semester);
    }


}
